package com.example.spring.transaction.dal;

import lombok.RequiredArgsConstructor;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author lei yu
 * @since 2024/06/05
 */
@Repository
@RequiredArgsConstructor
public class UserDaoImpl implements IUserDao {

    private final JdbcTemplate jdbcTemplate;

    @Override
    public void save() {
        jdbcTemplate.update("update emp set sal=sal+200 where empno=7499");
    }

    @Override
    public User getUser() {
        return jdbcTemplate.queryForObject("select * from emp where empno=7369",new BeanPropertyRowMapper<>(User.class));
    }

    @Override
    public void sub() {
        jdbcTemplate.update("update emp set sal=sal-200 where empno=7369");
    }


}
